<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$a = session_id();if(empty($a)) session_start();

include_once dirname(__FILE__).'/class/functions.php';
include_once(dirname(__FILE__).'/class/upload_class.php');
require_once dirname(__FILE__).'/class/user.class.php';
$logat = is_logat();
$db = new stdb();
$user=unserialize($_SESSION['userc']);

if($logat){
$max_size = 1024*1024*250; // the max. size for uploading
	
$my_upload = new file_upload;

$my_upload->upload_dir = dirname(__FILE__)."/tmp/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".png", ".zip", ".pdf"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
		
if(isset($_POST['Submit'])) {
    
        //print_r($_POST);
        mysql_safer();
	$my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
	$my_upload->the_file = $_FILES['upload']['name'];
	$my_upload->http_error = $_FILES['upload']['error'];
	$my_upload->the_mime_type = $_FILES['upload']['type']; // new in ver. 2.33
	$my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
	$my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
	$new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
	if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
		$full_path = $my_upload->upload_dir.$my_upload->file_copy;
		$info = $my_upload->get_uploaded_file_info($full_path);
		// ... or do something like insert the filename to the database
                $sql_insert="INSERT INTO  `file_table` (`FID` ,`nume` ,`nume_scurt` ,`descriere` ,`CAT` ,`AN` ,`status` ,`data` ,`type` ,`UID`)
                            VALUES (
                                                                     NULL ,  '".$_FILES['upload']['name']."',  '".$my_upload->file_copy."',  '".$_POST['descriere']."',  '".$_POST['categoria']."',  '".$_POST['anul']."', NULL , '".date("Y-m-d", time())."' ,  '".$my_upload->get_extension($full_path)."', '".$user->id."'
                                    )";
                $db->q($sql_insert);
                $result=$db->q("SELECT FID FROM file_table WHERE nume_scurt='".$my_upload->file_copy."'");
                $rows = mysql_fetch_array($result);
                foreach($_POST['meta'] as $meta)
                    if(isset($meta)&&strlen($meta)>3)
                         $db->q("CALL meta_in('".$meta."',".$rows[0].")");
	}
}



}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="icon" href="favicon.jpg" type="image/gif" sizes="16x16" /> 
        <link rel="stylesheet" type="text/css" href="./style/style.css" />
        <title></title>
    </head>
    <body>
        <? 
        
        if($logat){
        header_out();
        
        
        }
        else
        {
            header_login();
            
            }

                    ?>
        <div id="content">
            <div id="content_inside">
                    <div id="content_inside_sidebar">
                        <ul>
                            <li><a href ="<? echo $path;?>index.php#home_stuff" id="show_home"> Home</a><br />
                            </li><li><a href ="<? echo $path;?>index.php#telefon_stuff" id="show_tel"> Carte Telefon</a><br /></li>
                            <li><a href ="<? echo $path;?>index.php#rezervari_stuff" id="show_rezerv"> Rezervari</a><br /></li>    
                            <li><a href ="<? echo $path;?>index.php#download_stuff" id="show_down"> Downloads</a><br /></li> 
                                           
                         </ul>
                                 
                    </div>
            <div id="content_inside_main">
              <?if($logat){ ?> 
                <p>Max. filesize = <?php echo $max_size; ?> bytes.</p>
                        <form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>"><br>
                        <label for="upload">Select a file...</label><input type="file" name="upload" size="30"><br clear="all">
                    
                        <?
                        echo pt_rezervari("categorii", "categoria");
                        echo pt_rezervari("ani", "anul");
                        ?>
                         <textarea rows="3" cols="20" name="descriere" style="border: solid lightgrey;margin-top: 10px;float: left;width:550px;"> O mica descriere!   </textarea>                                                               <br/>
                                                                                        <h3> Etichete: </h3>
                        <input type="text" name="meta[]" value="">   <input type="text" name="meta[]" value="">  <input type="text" name="meta[]" value="">  <br/>
                        <input type="text" name="meta[]" value="">   <input type="text" name="meta[]" value="">  <input type="text" name="meta[]" value="">  <br/>
                        <a href="#" class="grey-button pcb"><span><input  type="submit" name="Submit" value="Submit"></span></a>
                         </form>
                            <br clear="all">
                        <p><?php echo $my_upload->show_error_string(); ?></p>
                        <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?> 
                
                  <? }
                  else 
                  { echo " Autentificati-va! ";}?>
            </div>

        
        
    </body>
    
    <? footer(); ?>
    
</html>